package com.Laboratory.util;

/**
 * @Author acok
 * @description: 序号自动补全，支持补全中间缺失代码、新增新序号
 * @Date 2023/1/3 16:51
 * @Version 1.0
 */
public class completionUtil {
    public static String autoCompletionEquipmentNo(String [] arr){
        String result="";
        int size=3;
        if(arr.length>0&&"001".equals(arr[0])){
            int endNum =Integer.parseInt(arr[arr.length-1]);
            if(endNum!=arr.length){
                for(int i=0;i< arr.length-1;i++){
                    int i1 = Integer.parseInt(arr[i]);
                    int i2= Integer.parseInt(arr[i+1]);
                    if(i2 - i1 >1){
                        String s=String.valueOf(i1 +1);
                        for (int j=0; j<size;j++){
                            if (s.length()<size){
                                s='0'+s;
                            }
                        }
                        result=s;
                        break;
                    }
                }
            }else {
                String s=String.valueOf(arr.length+1);
                for (int i=0;i<size;i++){
                    if (s.length()<size){
                        s='0'+s;
                    }
                }
                result=s;
            }
        }else {
            result="001";
        }
        return result;
    }
}
